﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ZSZ.AdminWeb.App_Start;
using ZSZ.CommonMvc;
using ZSZ.Iservice;

namespace ZSZ.AdminWeb.Controllers
{
    public class PermissionController : Controller
    {
        // GET: Permission
        public IPermissionService permissionService { get; set; }
        [CheckPermission("Permission.List")]
        public ActionResult List()
        {
            var pers = permissionService.GetAll();
            return View(pers);
        }

        [HttpPost]
        [CheckPermission("Permission.Delete")]
        public ActionResult Delete(long id) {
            permissionService.MarkDeleted(id);
            return Json(new JsonCommon { Status = "ok" });
        }
        [HttpGet]
        [CheckPermission("Permission.Edit")]
        public ActionResult Edit(long id)
        {
            var per = permissionService.GetById(id);
            return View(per);
        }
        [HttpPost]
        [CheckPermission("Permission.Edit")]
        public ActionResult Edit(long id, string name, string miaoshu) {
            permissionService.Update(id, name, miaoshu);
            return Json(new JsonCommon { Status = "ok" });
        }
        [HttpGet]
        [CheckPermission("Permission.Add")]
        public ActionResult Add() {
            return View();
        }
        [HttpPost]
        [CheckPermission("Permission.Add")]
        public ActionResult Add(string name, string miaoshu) {
            permissionService.AddNew(name,miaoshu);
            return Json(new JsonCommon { Status="ok"});
        }
        [HttpPost]
        [CheckPermission("Permission.Delete")]
        public ActionResult PiLiangShan(long[] ids) {
            foreach (var item in ids)
            {
                permissionService.MarkDeleted(item);
            }
            return Json(new JsonCommon { Status = "ok" });
        }
    }
}